<?php

/**
 * UserIdentity represents the data needed to identity a user.
 * It contains the authentication method that checks if the provided
 * data can identity the user.
 */
class UserIdentity extends CUserIdentity
{
	private $_id;
	private $_pseudo;
	private $_admin;

	public function authenticate()
	{		
		$record = Seliste::model()->findByAttributes(array('pseudo'=>$this->username));
		
		if ($record === NULL) {
			$this->errorCode=self::ERROR_USERNAME_INVALID;
		} elseif ($record->pwd!==md5($this->password)) {
			$this->errorCode=self::ERROR_PASSWORD_INVALID;
		} else {
			$this->_id = $record->id;
			$this->_pseudo = $record->pseudo;
			$this->_admin = $record->admin;
			$this->setState('login',$record->pseudo);
			$this->setState('id',$record->id);
			$this->setState('admin',$this->_admin);
			$this->errorCode=self::ERROR_NONE;
			$session=new CHttpSession;
			$session->open();
			$session["skin"] = $record->theme;
		}
		return !$this->errorCode;
		
	}
}